Tabset example in Quarto

Author

Nathan Teuscher

Published

September 19, 2025

Import analysis data

Code
data0  = read.csv(paste0(dir.data,'poppk.csv')) %>% rename_with(toupper)
# str(data0) 
data1 <- data0
data1 %<>% mutate(AMT = fton(AMT),
                  DV = fton(DV),
                  TIME = fton(TIME),
                  TAD = fton(TAD)) #change to numeric. Note: %<>% (magrittr package) updates lhs object.


##############
# Event ID 
# unique(data1$EVID) # 1 0
# 0=observation
# 1=dose
# 2=Other-type event.  The DV data  item  is  ignored.   Dose-related data  items  must  be zero.
# 4=dose after washout period

# quick checks
# names(data1)
#  [1] "C"    "ID"   "TIME" "TAD"  "DV"   "MDV"  "EVID" "AMT"  "ADDL" "II"   "WT"   "HV"   "CRCL" "AGE"  "SEX"  "FOOD" "RACE" "ALT"  "AST" 
# [20] "ALB" 

data1 %<>% mutate(EVIDf = case_when(EVID == 0 ~ 'Observation',
                                    EVID == 1 ~ 'Dose'),
                  EVIDf = factor(EVIDf, levels = c("Dose","Observation")))

# data1 %>% group_by(EVIDf) %>% tally()
# # A tibble: 2 × 2
#   EVIDf           n
#   <fct>       <int>
# 1 Dose          200
# 2 Observation  4472

data1 %<>% mutate(SEXf = factor(case_when(SEX==1~'Male',
                                          SEX==0~'Female'),
                                levels = c('Male','Female')))
data1 %<>% mutate(RACEf = factor(case_when(RACE==0~'Caucasian',
                                           RACE==1~'Black',
                                           RACE==2~'Asian',
                                           RACE==3~'Native American',
                                           RACE==4~'Pacific Islander',
                                           RACE==5~'Other',
                                           RACE==6~'Multiple',
                                           RACE==7~"Australian Aborigine",
                                           RACE==-99~'Missing'),
                                 levels = c('Caucasian','Black','Asian',
                                            'Native American','Pacific Islander','Other','Multiple',"Australian Aborigine",'Missing')))
data1 %<>% mutate(FOODf = factor(case_when(FOOD == 0 ~ 'Fasting',
                                           FOOD == 1 ~ 'Fed'),
                                 levels = c('Fasting','Fed')))
# data1 %>% group_by(SEXf) %>% distinct(ID) %>% tally()
# # A tibble: 2 × 2
#   SEXf       n
#   <fct>  <int>
# 1 Male     124
# 2 Female    76

# data1 %>% group_by(RACEf) %>% distinct(ID) %>% tally()
# # A tibble: 5 × 2
#   RACEf                n
#   <fct>            <int>
# 1 Caucasian          104
# 2 Black               18
# 3 Asian               49
# 4 Native American     18
# 5 Pacific Islander    11

# data1 %>% group_by(FOODf) %>% distinct(ID) %>% tally()
# # A tibble: 2 × 2
#   FOODf       n
#   <fct>   <int>
# 1 Fasting   179
# 2 Fed        21

Model diagnostics

  • Observed versus predicted have a trend that lies along the line of unity suggesting agreement between structural model and observed concentrations
  • All 3 conditional weighted residuals have a trend that lies along Y = 0 suggesting no bias in residuals with time, or predictions
  • The trend for the individual weighted residuals versus individual predictions is flat suggesting the residual error model is adequate
Code
dat <- gof_read_data(file = paste0(dir.models,'ppk3.tab')) 

gof(dat)

Code
temp <- extToTable(model = paste0(dir.models,'ppk3.ext')) %>% as.data.frame()
temp %<>% slice(1:n()-1) %>% 
  mutate(Theta.RSE = as.numeric(str_sub(Theta.RSE,start = 2,end = -2))*100,
         Omega.Est = as.numeric(Omega.Est)*100,
         Omega.RSE = as.numeric(str_sub(Omega.RSE,start = 2,end = -2))*100,
         Sigma.Est = as.numeric(Sigma.Est)*100,
         Sigma.Est = case_when(is.na(Sigma.Est) ~ "",TRUE ~ as.character(Sigma.Est)),
         Sigma.RSE = as.numeric(str_sub(Sigma.RSE,start = 2,end = -2))*100,
         Sigma.RSE = case_when(is.na(Sigma.RSE) ~ "",TRUE ~ as.character(Sigma.RSE)))
temp$Theta.ID <- c("CL (L/hr)","Vc (L)","Q (L/hr)","Vp (L)","Ka (1/hr)")
temp$Omega.ID <- c("IIV CL","IIV Vc","IIV Q","IIV Vp","IIV Ka")
temp$Sigma.ID <- c("Prop error (%)","","","","")
temp %>% flextable() %>% 
  colformat_num(big.mark = "", na_str = "") %>% 
  align(j=c(2,3,4,5,8,9), align = "right", part = "all") %>%
  align(j=c(1,4,7), align = "left", part = "all") %>%
  bold(bold = TRUE, part = "header") %>% 
  set_header_labels(Theta.ID = "Parameter",Theta.Est = "Estimate",Theta.RSE = "RSE",
                    Omega.ID = "IIV",Omega.Est = "%CV",Omega.RSE = "RSE",
                    Sigma.ID = "Residual Error",Sigma.Est = "Estimate",Sigma.RSE = "RSE") %>%
  add_footer_lines("IIV and residual errors calcualted as square root of omega and sigma variance values, respectively.") %>% 
  autofit()

Parameter

Estimate

RSE

IIV

%CV

RSE

Residual Error

Estimate

RSE

CL (L/hr)

19.82

2.62

IIV CL

35.67

4.59

Prop error (%)

31.26

1.32

Vc (L)

37.82

6.56

IIV Vc

49.88

12.50

Q (L/hr)

13.22

5.88

IIV Q

68.56

5.72

Vp (L)

324.7

3.72

IIV Vp

43.73

6.24

Ka (1/hr)

0.3007

4.05

IIV Ka

31.77

8.80

IIV and residual errors calcualted as square root of omega and sigma variance values, respectively.